{% extends "../base.html" %}

{% block title %}Edit task{% endblock %}
{% block header %}Edit task{% endblock %}

{% block content %}
		<a href="/projects">Projects</a>/
		<a href="/tasks?projectId={{ task.project.key }}">Tasks</a>

		<form method="POST" action="/saveTask">
			<table>
				<tr>
					<td>
						<label for="no">No: </label>
					</td>
					<td>
					{% if canEdit %}
						<input id="no" name="no" value="{{ task.index }}"></input>		
					{% else %}
						{{task.no}}
					{% endif %}
					
					</td>
				</tr>
				<tr>
					<td>
						<label for="taskName">Task name: </label>
					</td>
					<td>
					{% if canEdit %}
						<input id="taskName" maxlength="128" style="width: 400" name="taskName" value="{{ task.name }}"></input>		
					{% else %}
						{{task.name}}
					{% endif %}
					</td>
				</tr>
				<tr>
					<td>
						<label for="description">Description: </label>
					</td>
					<td>
					{% if canEdit %}
						<textarea id="description" name="description" rows="3" cols="60">{{task.description}}</textarea>		
					{% else %}
						{{task.description}}
					{% endif %}
					</td>
				</tr>
				<tr>
					<td>
						<label for="description">Description: </label>
					</td>
					<td>
					{% if canEdit %}
						<select name="priority" id="priority">
							<option value="0" {% ifequal task.priority 0 %}selected="selected"{% endifequal %}>Low</option>
							<option value="1" {% ifequal task.priority 1 %}selected="selected"{% endifequal %}>Medium</option>
							<option value="2" {% ifequal task.priority 2 %}selected="selected"{% endifequal %}>High</option>
						</select>
					{% else %}
						{% ifequal task.priority 0 %}Low{% endifequal %}
						{% ifequal task.priority 1 %}Medium{% endifequal %}
						{% ifequal task.priority 2 %}High{% endifequal %}
					{% endif %}
					</td>
				</tr>
				<tr>
					<td>
						<label for="assignedTo">Assign to: </label>
					</td>
					<td>
					{% if canEdit %}
						<select name="assignedTo" id="assignedTo">
							{% for participant in participants %}
							<option {% ifequal participant.key task.assignedTo.key %} selected="selected" {% endifequal %}>{{ participant.user.email }}</option>
							{% endfor %}
						</select>
					{% else %}
						{{ task.assignedTo.user.nickname }}
					{% endif %}
					</td>
				</tr>
				<tr>
					<td>
						<label for="status">Status: </label>
					</td>
					<td>
					{% if assignedToMe %}
						{% ifnotequal task.status 'CANCELLED' %} 
						{% ifnotequal task.status 'FINISHED' %} 
						<select name="status" id="status">
							<option selected="selected">{{ task.status }}</option>
							{% ifequal task.status 'CREATED' %}
							<option>ACCEPTED</option>
							<option>CANCELLED</option>
							{% else %}
								{% ifequal task.status 'ACCEPTED' %}
								<option>FINISHED</option>
								<option>SUSPENDED</option>
								<option>CANCELLED</option>
								{% else %}
									{% ifequal task.status 'SUSPENDED' %}
										<option>RESUMED</option>
										<option>CANCELLED</option>
									{% else %}
										{% ifequal task.status 'RESUMED' %}
											<option>FINISHED</option>
											<option>SUSPENDED</option>
											<option>CANCELLED</option>
										{% endifequal %}
										
									{% endifequal %}
									
								{% endifequal %}
							{% endifequal %}
							<option>
						</select>
						 {% else %}
							{{ task.status }}
						{% endifnotequal %} 
						{% else %}
							{{ task.status }}
						{% endifnotequal %} 
					{% else %}
						{{task.status}}
					{% endif %}
					</td>
				</tr>
			</table>
			<input type="hidden" name="taskId" value="{{ task.key }}"></input>
			<input type="submit" value="Save"></input>
			
		</form>
		<h4> Comments </h4>
		
		<table cellpadding="0" cellspacing="0" class="comments">
		{% for comment in comments %}
			<tr>
				<td style="font-weight:bold">{{comment.creator.nickname }}({{ comment.createdAt.day }}.{{ comment.createdAt.month }}.{{ comment.createdAt.year }} {{ comment.createdAt.hour }}.{{ comment.createdAt.minute }})</td>
			</tr>
			<tr>
				<td class="text">{{ comment.text }}</td>
			</tr>
		{% endfor %}
		</table>
		
		<form action="/saveComment" method="post">
			<textarea name="commentText" id="commentText" rows="7" cols="60"></textarea>
			<input type="hidden" name="taskId" value="{{ task.key }}"></input>
			<input type="submit" value="Add comment" ></input>			
		</form>
{% endblock %}
